/**
 * bsw_hash.h
 *
 * 竹影半墙
 * 2023.10
 */
#ifndef BSW_HASH_H
#define BSW_HASH_H

#include "bsw_list.h"

typedef int (*bsw_hash_f)(void *k);
typedef int (*bsw_compare_f)(void *d, void *k);
typedef int (*bsw_startof_f)(bsw_list_node_s *n);

typedef struct bsw_hash     bsw_hash_s;
typedef struct bsw_hash_app bsw_hash_app_s;

struct bsw_hash_app {
    bsw_hash_f    hash;
    bsw_startof_f startof;
    bsw_compare_f compare;
    int size;
};

#if 0
#endif
bsw_hash_s * bsw_hash_init(bsw_hash_app_s *app);
void bsw_hash_close(bsw_hash_s *h);

int  bsw_hash_size(bsw_hash_s *h);
void bsw_hash_add(bsw_hash_s *h, bsw_list_node_s *n, void *k);
void * bsw_hash_find(bsw_hash_s *h, void *k);
void * bsw_hash_del (bsw_hash_s *h, void *k);

/**
 * 依次遍历在哈希表 @h 中的各个元素
 */
void * bsw_hash_each(bsw_hash_s *h);

/**
 * 遍历哈希表 @h 并且将所遍历结点从哈希表中删除
 * 返回所遍历目标元素
 */
void * bsw_hash_each_del(bsw_hash_s *h);

/**
 * 重置哈希表 @h 以便从头开始遍历
 */
void   bsw_hash_each_reset(bsw_hash_s *h);
#endif